//TODO:一个页面一个,比如home页面对应的数据叫做home.js，这部分代码需要做
import api from '../../assets/api/index'   //ajax
import {lc} from './../types/index'
import {sessionStorage} from './../../storage/storage';

const state = {
  targetId:sessionStorage.get(lc.USER_ORDER_STATUS),
  myQrCodeData:sessionStorage.get(lc.USER_MYQRCODE),
  weiQrCodeData:sessionStorage.get(lc.USER_WEIQRCODE)
};

const actions = {
    orderStatus({commit},status){
      commit(lc.USER_ORDER_STATUS,status);
    },
    myQrCode({commit},status){
      commit(lc.USER_MYQRCODE,status);
    },
    weiQrCode({commit},status){
      commit(lc.USER_WEIQRCODE,status);
    }

};

const mutations ={
  [lc.USER_ORDER_STATUS](state,status){
    state.targetId = status.id;
    sessionStorage.set(lc.USER_ORDER_STATUS,status.id);
  },
  [lc.USER_MYQRCODE](state,status){
    if(state.myQrCodeData){
      return;
    }
    state.myQrCodeData = status.data;
    sessionStorage.set(lc.USER_MYQRCODE,status.data);
  },
  [lc.USER_WEIQRCODE](state,status){
    state.weiQrCodeData = status.data;
    sessionStorage.set(lc.USER_WEIQRCODE,status.data);
  }
};


const getters = {
  targetId (state){
    return state.targetId
  },
  myQrCodeData (state){
    return state.myQrCodeData == null ? null : state.myQrCodeData
  },
  weiQrCodeData (state){
    return state.weiQrCodeData == null ? null : state.weiQrCodeData
  }
};


export default {
  state,
  actions,
  mutations,
  getters
}






// targetId (state){
//   return state.targetId == null ? 'AllOrders' : state.targetId
// },






























